<template>
    <customNavigationBar title="代理商品选择" />

    <!-- <view class="unpaidNum">
        <view class="text">待支付费用(元)</view>
        <view class="num">￥{{ unpaidAgencyFees?.agentAmount - unpaidAgencyFees?.payAmount }}</view>
    </view> -->

    <view class="items">
        <view class="item" v-for="(item, index) in payOptions" :key="item.title" @click="checkIndex = index">
            <image class="gift" src="/static/home/icon_gift.png" mode=""></image>

            <view class="text">
                <view>{{ item.title }}</view>
                <view class="num">￥{{ item.num }}</view>
            </view>

            <view class="checkBox" :class="index === checkIndex && 'checked'">
                <image src="/static/common/icon_checked_white.png"></image>
            </view>
        </view>
    </view>

    <view class="bottom">
        <view class="total">共计：￥ {{ payOptions[checkIndex]?.num }}</view>
        <view class="paySubmit" @click="goPay">去支付</view>
    </view>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { onShow } from '@dcloudio/uni-app';
import { homeApis } from '@/utils/apis';

const checkIndex = ref(0);

const payOptions = ref([]);

const goPay = () => {
    uni.navigateTo({
        url: '/pages_finance/agencyFeePayMethod/agencyFeePayMethod?price=' + payOptions.value[checkIndex.value].num
    });
};

onShow(() => {
    getAgencyPayment();
});

const unpaidAgencyFees = ref(null);
const getAgencyPayment = async () => {
    let res = await homeApis.getAgencyPayment();
    unpaidAgencyFees.value = res.data;

    if (res.data.payAmount === 0) {
        payOptions.value = [
            {
                title: '代理商品购买',
                num: res.data.agentAmount
            }
            // {
            //     title: '定金费用(元)',
            //     num: res.data.agentAmount * 0.1
            // }
        ];
    } else {
        payOptions.value = [
            {
                title: '剩余费用(元)',
                num: res.data.agentAmount - res.data.payAmount
            }
        ];
    }
};
</script>

<style lang="scss" scoped>
.unpaidNum {
    padding-top: 80rpx;
    .text {
        text-align: center;
        font-size: 28rpx;
        color: #999999;
        margin-bottom: 24rpx;
    }
    .num {
        font-weight: bold;
        font-size: 56rpx;
        color: #333333;
        text-align: center;
    }
}

.items {
    margin-top: 44rpx;
    padding: 0 24rpx;

    .item {
        width: 100%;
        margin-bottom: 20rpx;
        width: 100%;
        height: 154rpx;
        background: #f2f3f5;
        border-radius: 16rpx;
        display: flex;
        align-items: center;
        padding: 0 40rpx 0 0;

        .gift {
            width: 160rpx;
            height: 160rpx;
            margin-right: 32rpx;
        }

        .text {
            view {
                font-size: 28rpx;
                color: #333333;
            }
            .num {
                font-size: 40rpx;
                color: #fa5151;
                margin-top: 16rpx;
            }
        }

        .checkBox {
            margin-left: auto;
            width: 40rpx;
            height: 40rpx;
            border: 2rpx solid #707070;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 50%;
            transition: 0.3s;
            image {
                width: 21rpx;
                height: 15rpx;
                opacity: 0;
            }
            &.checked {
                width: 40rpx;
                height: 40rpx;
                background: #2c72ff;
                border: 2rpx solid #2c72ff;
                image {
                    opacity: 1;
                }
            }
        }
    }
}
.bottom {
    position: fixed;
    bottom: env(safe-area-inset-bottom);
    left: 0;
    width: 100%;
    padding: 30rpx 42rpx;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: #fff;
    .total {
        font-size: 32rpx;
        color: #999999;
    }
    .paySubmit {
        width: 244rpx;
        height: 80rpx;
        background: #2c72ff;
        border-radius: 40rpx;
        font-size: 28rpx;
        color: #ffffff;
        line-height: 80rpx;
        text-align: center;
    }
}
</style>
